package com.ssy.lingxi.common.constant.manage;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商城适用环境 - enum
 * @author fhj
 * @date 2020/07/30
 * @version 2.0.0
 */
public enum ShopEnvironmentEnum {

    WEB(1, "Web"),
    H5(2, "H5"),
    APPLETS(3, "小程序"),
    APP(4, "App"),
    INVALID_ENVIRONMENT(5, "无效环境");

    private final Integer code;

    ShopEnvironmentEnum(Integer code, String message) {
        this.code = code;
    }

    /**
     * 根据code获取message
     * */
    public static String getMessage(Integer code) {
        String key = ShopEnvironmentEnum.class.getSimpleName().concat(".");
        ShopEnvironmentEnum shopEnvironmentEnum = Arrays.stream(ShopEnvironmentEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return shopEnvironmentEnum != null ? shopEnvironmentEnum.getMessage() : key.concat(String.valueOf(ShopEnvironmentEnum.INVALID_ENVIRONMENT.getCode()));
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(),this.code);
    }
}
